package com.example.intelligentattendancesystem.controller;

import com.example.intelligentattendancesystem.pojo.User;
import com.example.intelligentattendancesystem.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author
 * @version 1.0
 * @className UserController
 * @since 1.0
 */
@RestController
@RequestMapping("smartAttendance/user")
public class UserController {

    @Autowired
    UserService userService;
    /**
     * 获取用户列表
     * @return 返回所有的员工
     */
    @RequestMapping("/userList")
    public List<User> getUserList(){
        List<User> userListService = userService.getUserListService();
        return userListService;
    }

    /**
     * 通过用户id获取用户
     * @param userId 用户的id
     * @return 返回用户对象
     */
    @RequestMapping("getUser")
    public User getUser(int userId){
        User userService1 = userService.getUserService(userId);
        return userService1;
    }
    /**
     * 通过用户id列表获取用户列表
     * @param userIds 用户的ids
     * @return 返回用户对象
     */
    @RequestMapping("getUsers")
    public List<User> getUsers(@RequestBody List<Integer> userIds){
//        System.out.println(userIds);
        List<User> users = userService.getUsersService(userIds);
        return users;
    }

    /**
     * 设置用户信息
     * @param user 修改好的用户
     * @return 成功为新用户，失败为旧用户
     */
    @RequestMapping("setUser")
    public User setUser(User user){
        User user1 = userService.updateUserService(user);
        return user1;
    }

    /**
     * 通过用户id删除用户
     * @param userId 用户id
     * @return
     */
    @RequestMapping("deleteUser")
    public boolean deleteUser(int userId){
        boolean b = userService.deleteUserService(userId);
        return b;
    }

}
